package study.javabasic.Thread;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;

/**
 * Created by zhangshuhan on 2019/3/13.
 */
public class TestSimDateFormate {

    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier= new CyclicBarrier(100);
        for (int i = 0; i < 100; i++) {
          new Thread(new CountDownLatchA(cyclicBarrier),String.valueOf(i)).start();
        }
    }
}

class CountDownLatchA implements Runnable {

    public static final ThreadLocal<SimpleDateFormat> FULL_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
    public static final ThreadLocal<SimpleDateFormat> DATE_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyy-MM-dd"));
    public static final ThreadLocal<SimpleDateFormat> TIME_FORMAT = ThreadLocal.withInitial(() -> new SimpleDateFormat("HH:mm:ss"));
    private static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    private CyclicBarrier cyclicBarrier;
    public CountDownLatchA(CyclicBarrier cyclicBarrier) {
        this.cyclicBarrier = cyclicBarrier;
    }

    @Override
    public void run() {
        try {
            System.out.println("进入等待");
            cyclicBarrier.await();
          /*  simpleDateFormat.parse("2013-03-13");*/
            DATE_FORMAT.get().parse("2013-03-13");
        } catch (ParseException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (BrokenBarrierException e) {
            e.printStackTrace();
        }
        System.out.println("完成任务");

    }
}